﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Glucometer.UserInterface
{
    public partial class BlinkingBattery : UserControl
    {

        private Timer _blinkingTimer;

        public BlinkingBattery()
        {
            InitializeComponent();
            picBoxBattery.Image = Properties.Resources.level_41;
            _blinkingTimer = new Timer();
            _blinkingTimer.Tick += new EventHandler(_blinkingTimer_Tick);
        }

        void _blinkingTimer_Tick(object sender, EventArgs e)
        {
            this.Visible = !this.Visible;
        }

        public void startBlinking(int blinkRate)
        {
            _blinkingTimer.Interval = 1000 / blinkRate;
            _blinkingTimer.Start();
        }

        public void stopBlinking()
        {
            _blinkingTimer.Stop();
            this.Visible = true;
        }

        public int BatteryLevel
        {
            set 
            {
                if (value == 0)
                    picBoxBattery.Image = Properties.Resources.level_01;
                else if (value == 1)
                    picBoxBattery.Image = Properties.Resources.level_11;
                else if (value == 2)
                    picBoxBattery.Image = Properties.Resources.level_21;
                else if (value == 3)
                    picBoxBattery.Image = Properties.Resources.level_31;
                else if (value == 4)
                    picBoxBattery.Image = Properties.Resources.level_41;
                else
                {
                    stopBlinking();
                    this.Visible = false;
                }
            }
        }
    }
}
